#region license
// KenEgozi.com - my blog engine
// This project is licensed under the MIT License
//
//Copyright (c) 2007, Ken Egozi
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
#endregion

using Castle.ActiveRecord;
using Castle.Components.Validator;

namespace KenEgozi.Com.Domain.Aggregates.Post
{
	[ActiveRecord]
	public class Comment
	{
		private readonly int _id = default(int);
		private readonly Lifecycle _lifecycle = new Lifecycle();
		private string _content;
		private string _name;
		private string _email;
		private string _homepage;
		private string _ipAddress;
		private Post _post = null;
		private CommentStatus _status;

		#region constructor
		public Comment()
		{
		}
		public Comment(string content, string name, string email, string homepage, string ipAddress)
		{
			_content = content;
			_name = name;
			_email = email;
			_homepage = homepage;
			_ipAddress = ipAddress;
			_status = CommentStatus.Unknown;
		}
		public Comment(string content, string name, string email, string homepage, string ipAddress, Post post)
			: this(content, name, email, homepage, ipAddress)
		{
			_post = post;
		}
		#endregion

		[PrimaryKey(Access = PropertyAccess.NosetterCamelcaseUnderscore)]
		public virtual int Id
		{
			get { return _id; }
		}

		[Nested(Access = PropertyAccess.NosetterCamelcaseUnderscore)]
		public virtual Lifecycle Lifecycle
		{
			get { return _lifecycle; }
		}

		[Property]
		public string Content
		{
			get { return _content; }
			set { _content = value; }
		}

		[Property]
		[ValidateEmail]
		public string Email
		{
			get { return _email; }
			set { _email = value; }
		}
		[Property]
		[ValidateNonEmpty]
		public string Name
		{
			get { return _name; }
			set { _name = value; }
		}
		[Property]
		public string Homepage
		{
			get { return _homepage; }
			set { _homepage = value; }
		}

		[Property]
		public string IpAddress
		{
			get { return _ipAddress; }
			set { _ipAddress = value; }
		}
		[BelongsTo("PostId")]
		public virtual Post Post
		{
			get { return _post; }
			set { _post = value; }
		}

		[Property(Access = PropertyAccess.NosetterCamelcaseUnderscore)]
		public CommentStatus Status
		{
			get { return _status; }
		}

		public void Approve()
		{
			_status = CommentStatus.Approved;
		}

		public void HeyItsSpam()
		{
			_status = CommentStatus.Spam;
		}

		public void IsProbablyOk()
		{
			_status = CommentStatus.ProbableOk;
		}

		public void BelongsTo(Post post)
		{
			_post = post;
		}
	}
}
